
// PrintTestView.cpp : implementation of the CPrintTestView class
//

#include "stdafx.h"
// SHARED_HANDLERS can be defined in an ATL project implementing preview, thumbnail
// and search filter handlers and allows sharing of document code with that project.
#ifndef SHARED_HANDLERS
#include "PrintTest.h"
#endif

#include "PrintTestDoc.h"
#include "PrintTestView.h"

#include "TitleDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CPrintTestView

IMPLEMENT_DYNCREATE(CPrintTestView, CView)

BEGIN_MESSAGE_MAP(CPrintTestView, CView)
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CPrintTestView::OnFilePrintPreview)
	ON_WM_CONTEXTMENU()
	ON_WM_RBUTTONUP()
	ON_COMMAND(ID_TITLE, &CPrintTestView::OnTitle)
END_MESSAGE_MAP()

// CPrintTestView construction/destruction

CPrintTestView::CPrintTestView()
{
	// TODO: add construction code here

}

CPrintTestView::~CPrintTestView()
{
}

BOOL CPrintTestView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

// CPrintTestView drawing

void CPrintTestView::OnDraw(CDC* pDC)
{
	CPrintTestDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	// TODO: add draw code for native data here
	RECT rc; 
	int angle; 
	HFONT hfnt, hfntPrev; 
	LPTSTR lpszRotate = TEXT("String to be rotated."); 

	// Allocate memory for a LOGFONT structure. 
	PLOGFONT plf = (PLOGFONT) LocalAlloc(LPTR, sizeof(LOGFONT)); 

	// Specify a font typeface name and weight. 
	lstrcpy(plf->lfFaceName, TEXT("Arial")); 
	plf->lfWeight = FW_NORMAL; 

	// Retrieve the client-rectangle dimensions. 
	GetClientRect( &rc ); 

	// Set the background mode to transparent for the 
	// text-output operation. 
	pDC->SetBkMode( TRANSPARENT); 

	// Draw the string 36 times, rotating 10 degrees 
	// counter-clockwise each time. 

	for (angle = 0; angle < 3600; angle += 100) 
	{ 
		plf->lfEscapement = angle; 
		hfnt = CreateFontIndirect(plf); 
		hfntPrev = (HFONT)pDC->SelectObject(hfnt); 
		pDC->TextOut(rc.right / 2, rc.bottom / 2, 
			lpszRotate, lstrlen(lpszRotate)); 
		pDC->SelectObject(hfntPrev); 
		DeleteObject(hfnt); 
	} 

	// Reset the background mode to its default. 
	pDC->SetBkMode( OPAQUE); 

	// Free the memory allocated for the LOGFONT structure. 
	LocalFree((LOCALHANDLE) plf); 
}


// CPrintTestView printing


void CPrintTestView::OnFilePrintPreview()
{
#ifndef SHARED_HANDLERS
	AFXPrintPreview(this);
#endif
}

BOOL CPrintTestView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CPrintTestView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
{
	// TODO: add extra initialization before printing
	OnDraw( pDC );
}

void CPrintTestView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

void CPrintTestView::OnRButtonUp(UINT /* nFlags */, CPoint point)
{
	ClientToScreen(&point);
	OnContextMenu(this, point);
}

void CPrintTestView::OnContextMenu(CWnd* /* pWnd */, CPoint point)
{
#ifndef SHARED_HANDLERS
	theApp.GetContextMenuManager()->ShowPopupMenu(IDR_POPUP_EDIT, point.x, point.y, this, TRUE);
#endif
}


// CPrintTestView diagnostics

#ifdef _DEBUG
void CPrintTestView::AssertValid() const
{
	CView::AssertValid();
}

void CPrintTestView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CPrintTestDoc* CPrintTestView::GetDocument() const // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CPrintTestDoc)));
	return (CPrintTestDoc*)m_pDocument;
}
#endif //_DEBUG


// CPrintTestView message handlers


void CPrintTestView::OnTitle()
{
	// TODO: Add your command handler code here
	CTitleDlg dlg;
	dlg.m_strTitle = GetDocument()->GetTitle();
	if( IDOK == dlg.DoModal() )
	{
		GetDocument()->SetTitle( dlg.m_strTitle );
	}
}
